#-*- coding: utf8 -*-
from tutor.scripts import *
from tutor.plugins.sympy import *

def dot_prod(u, v):
    return sum(ui * vi for (ui, vi) in zip(u, v))

# Entradas
with display_block('Entradas'):
    func = x * y + randint(1, 4) * z ** 2 / Two
    point = (randint(-4, 4) / Two, randint(-4, 4) / Two, randint(-4, 4) / Two)
    direction = (randint(-4, 4), randint(-4, 4), randint(-4, 4))

# Resultados auxiliares
with display_block('Variáveis auxiliares'):
    var_symbs = list(map(var, 'xyzw'))
    var_subs = list(zip(var_symbs, point))
    grad = list(func.diff(x) for x in var_symbs)
    grad = list(df_i.subs(var_subs) for df_i in grad)
    _dir_norm = sqrt(dot_prod(direction, direction))
    normed_direction = list(x / _dir_norm for x in direction)

# Resultados
with display_block('Respostas'):
    correct = dot_prod(grad, normed_direction)
    correct_neg = -correct
    non_normalized = dot_prod(grad, direction)
    non_normalized_neg = -non_normalized
    gradient = sqrt(dot_prod(grad, grad))
    gradient_neg = -gradient
    distractor = dot_prod(grad, (1, 1, 1, 1))
    distractor_neg = -distractor

